import torch
import torch.nn as nn


def build_mlp(dims: [], activation: nn = None, is_raw_out: bool = True) -> nn.Sequential:
    if activation is None:
        activation = nn.ReLU
    net_list = []
    for i in range(len(dims)-1):
        net_list += [nn.Linear(dims[i], dims[i+1]), activation()]
    if is_raw_out:
        net_list.pop()
    return nn.Sequential(*net_list)


def layer_init_with_orthogonal(layer, std=1.0, bias_const=1e-6):
    torch.nn.init.orthogonal_(layer.weight, std)
    torch.nn.init.constant_(layer.bias, bias_const)
